import Vue from 'vue'
import VueRouter from 'vue-router'
import Admin from "../views/Admin/Admin";



Vue.use(VueRouter)
export const AdminMap ={
//系统管理
  path :'/Admin',
  name :'Admin',
  component : Admin,
  redirect: '/Admin/UserManage',
  children : [
    {
      //用户管理
      path :'UserManage',
      name :'UserManage',
      component : ()=>import('@/views/Admin/UserManage')
    },
    //名片管理
    {
      path :'CardManage',
      name :'CardManage',
      component : ()=>import('@/views/Admin/CardManage')
    },
    //名片审核
    {
      path :'auditManage',
      name :'auditManage',
      component : ()=>import('@/views/Admin/auditManage')
    },
    //名片修改
    {
      path :'editCard',
      name :'editCard',
      component : ()=>import('@/views/Admin/EditCard')
    },
  ]

}
const routes = [
  AdminMap,
  //登录
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/login.vue')
  },
  //注册
  {
    path: '/register',
    name: 'Register',
    component: () => import('../views/register.vue')
  },
  //首页
  {
    path: '/index',
    name: 'Index',
    component: () => import('../views/index.vue')
  },
  //名片详情
  {
    path: '/ecarddetail',
    name: 'ecarddetail',
    component: () => import('../views/ecardDetail.vue')
  },
  //学术成果
  {
    path: '/paper',
    name: 'paper',
    component: () => import('../views/Paper.vue')
  },
  //预选单
  {
    path :'/myprimary',
    name :'myprimary',
    component: () => import('../views/myprimary.vue')
  },
  //异常
  {
    path :'/waring',
    name :'waring',
    component: () => import('../views/waring.vue')
  },
  //教师维护
  {
    path :'/tecidcard',
    name :'tecidcard',
    component: () => import('../views/TecidCard.vue')
  }
]


const router = new VueRouter({
  // mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to, from, next) => {
  console.log(to)
  let isLogin = window.sessionStorage.getItem('user');
  if (isLogin) {
//如果用户信息存在则往下执行。
    next()
  } else {
//如果用户token不存在则跳转到login页面
    if (to.path === '/login' || to.path === '/register')  {
      next()
    } else {
      next('/login')
    }
  }
})

export default router
